package com.ikas.ai.framework.statistics.function;

import com.ikas.ai.framework.statistics.StatisticType;

import java.util.List;
import java.util.Objects;

/**
 * @Description: 空值比例
 * @Author: qi.yilai
 * @Date: 2023/10/27 17:54
 * @Version: 1.0.0
 **/
public class NullRatioCalcFunction implements CalcFunction<List, Long, Long, Float> {

    @Override
    public Float calculate(List list) {
        float size = list.size();
        long nullSize = list.stream().filter(Objects::isNull).count();
        return nullSize / size;
    }

    @Override
    public Float calculate(List list, Long size, Long nullSize) {
        return (float)nullSize/ size;
    }


    @Override
    public StatisticType type() {
        return StatisticType.NULL_RATIO;
    }
}
